<?php
namespace common\models;


class WithdrawLog extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'withdraw_log';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['member_id'], 'required'],
            [['member_id', 'b_type', 'state', 'callback_state', 'send_nums', 'create_time', 'update_time'], 'integer'],
            [['money', 'fee', 'price'], 'number'],
            [['collect_info'], 'string'],
            [['type', 'admin_user'], 'string', 'max' => 32],
            [['txid'], 'string', 'max' => 128],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '会员id',
            'money' => '提现金额',
            'fee' => '手续费',
            'b_type' => '提现的账本',
            'type' => '收款的类型 如wechat wallet等',
            'collect_info' => '收款信息',
            'state' => '1申请中 2审核通过 3驳回 4完成',
            'txid' => '交易id  提现到钱包有此值',
            'callback_state' => '0确认中 1成功 2失败',
            'send_nums' => '发送次数',
            'price' => '价格',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'admin_user' => '操作人',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;
		foreach ($data as $k=>&$v){
		    $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
            $v['text']        = '提现';
        foreach ($extends as $extend) {
        }
    }

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}
    /*
        * 提现列表
        * whereArr 条件
        * params 基本参数 包含 field order page limit
        * extends  扩展信息 一些相关的信息
        *
    */
    public static function withdrawList($whereArr,$params,$extends=array())
    {
        $model  = self::find();
        $where  = $whereArr['where'];
        $whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
        $models = self::queryFormart($model,$where,$params,$whereAnd);
        $model  = $models['model'];
        self::$pages = $models['pages'];

        $data  = $model->asarray()->all();
        if(!$data) return array();

        //扩展信息
        if(!$extends) return $data;
        return $data;
    }

    public static function getWithdrawLog($id)
    {
        return self::find()->where(['id'=>$id])->asarray()->one();
    }
}